package javagame;

import gamesound.*;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Options extends BasicGameState {
	
	private Image slika;
	private Image on;
	private Image off;
	private int slikaX;
	private int slikaY;
	//true on, false off
	private Zvuk zvuk;
	private boolean music;
	private boolean soundfx;
	private boolean fullScreen;
	
	private int mouseX, mouseY;
	
	public Options (int state) {
	}

	public int getID() {
		return 2;
	}

	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
		slikaX = 0;
		slikaY = 0;
		zvuk = Zvuk.dohvZvuk();
		slika = new Image("res/opt.png");
		on = new Image("res/on.png");
		off = new Image("res/off.png");
		music = true;
		soundfx = true;
		fullScreen = false;
	}

	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.drawImage(slika, slikaX, slikaY);
		
		//music
		if(music) g.drawImage(on, 653, 307);
		else g.drawImage(off, 653, 307);
		
		//sound fx
		if(soundfx) g.drawImage(on, 653, 343);
		else g.drawImage(off, 653, 343);
		
		//full screen
		if(fullScreen) g.drawImage(on, 653, 378);
		else g.drawImage(off, 653, 378);
		
	}
	
	public void fullScreenOnOff (GameContainer gc) throws SlickException {
		if (gc.getInput().isKeyDown(Input.KEY_F)) {
			if (gc.isFullscreen()) {
				gc.setFullscreen(false);
			}
			else {
				gc.setFullscreen(true);
			}
		}
	}

	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		Input input = gc.getInput();
		mouseX = input.getMouseX();
	  	mouseY = input.getMouseY();
		
	  	fullScreenOnOff(gc);
	  	if (gc.isFullscreen()) {
	  		fullScreen = true;
	  	}
	  	else {
	  		fullScreen = false;
	  	}
		
	  	//music
	  	if ((mouseX > 254 && mouseX < 639) && (mouseY > 304 && mouseY < 334)) {
			if (input.isMousePressed(0)) {
				if(music == true) music=false;
				else music=true;
			}
		}
	  	
	  	//sound fx
	  	if ((mouseX > 254 && mouseX < 639) && (mouseY > 340 && mouseY < 370)) {
			if (input.isMousePressed(0)) {
				if(soundfx == true) soundfx=false;
				else soundfx=true;
			}
		}
	  	
	  	//full screen
	  	if ((mouseX > 254 && mouseX < 639) && (mouseY > 375 && mouseY < 405)) {
			if (input.isMousePressed(0)) {
				if(fullScreen == true) fullScreen=false;
				else fullScreen=true;
			}
		}
	  	
	  	if(fullScreen == true) {
			gc.setFullscreen(true);
		}
		else {
			gc.setFullscreen(false);
		}
		if (music) {
	  		zvuk.setMusic(true);
	  	}
	  	else {
	  		zvuk.setMusic(false);
	  	}
	  	zvuk.pustiMuziku();
	  	if (soundfx) {
	  		zvuk.setSoundfx(true);
	  	}
	  	else {
	  		zvuk.setSoundfx(false);
	  	}
	  	
	  	//ok
	  	if ((mouseX > 312 && mouseX < 712) && (mouseY > 599 && mouseY < 698)) {
			if (input.isMousePressed(0)) {
				sbg.enterState(0);
			}
		}

	}
	
}
